﻿import jieba
counts = {}
txt = open("D://test.txt",encoding="utf-8").read()
words = jieba.lcut(txt)
for word in words:
    if len(word)==1:
        continue
    else:
        counts[word] = counts.get(word,0)+1

items = list(counts.items())
items.sort(key=lambda y:y[1],reverse=True)
for i in range(5):
    word,count = items[i]
    test = open("output.txt", "a",encoding="utf-8")
    test.write('"{}"====={}次     \n'.format(word, count))












